package com.example.repair

import androidx.lifecycle.ViewModel
import com.example.base.http.ApiServer
import com.example.base.mvi.BaseViewModel
import com.example.base.mvi.RequestType
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class RepairViewModel @Inject constructor(val apiServer: ApiServer): BaseViewModel<RepairIntent>() {
    override fun handlerIntent(it: RepairIntent) {
        when(it){
            is RepairIntent.getRepairs->{
                httpRequest(apiServer.getRepairs())
            }
            is RepairIntent.getRepairByNum->{
                httpRequest(apiServer.getRepairByNum(it.num), RequestType.REPIRITM)
            }
            is RepairIntent.getRepairByUser->{
                httpRequest(apiServer.getRepairByUser(it.user))
            }
            is RepairIntent.deleteRepair->{
                httpRequest(apiServer.deleteRepair(it.id), RequestType.DELETE)
            }

            is RepairIntent.addRepair->{
                httpRequest(apiServer.addRepair(toBody(it.bean)))
            }

            is RepairIntent.getRepirById->{
                httpRequest(apiServer.getRepairById(it.id))
            }
            is RepairIntent.updataRepair->{
                httpRequest(apiServer.updateRepair(it.id, toBody(it.bean)), RequestType.UPDATE)
            }
            else->{}
        }
    }
}